



import { log } from 'console';
import { Searchtable } from './Table'
import { AdvancedSearchForm } from './searchFrom'

import { noticelist } from '@/api1/notice/index'

import dayjs from 'dayjs';
import React, { useEffect, useState } from 'react';
interface searchFromtype {
  size: number,
  page: number,
  createTime?:string
}
export const NoticeList: React.FC = () => {
  const [searchFormData, setSearchFormData] = useState<searchFromtype>({ size: 10, page: 0 });
  const [data, setData] = useState<DataType[]>([]); // Make data reactive
  const [total, setTotal] = useState<number>(0)

  const handlePageChange = (page: number, pageSize?: number) => {
    // 这里可以添加处理分页逻辑，例如更新 searchFrom 中的 current 字段
    // 并且调用 getlist 方法来获取新的数据
    getlist({ ...searchFormData, page: (page-1).toString(), size: pageSize?.toString() || '10' });
  };
  const getlist = (values: any) => {
    noticelist(values).then((e: any) => {
     setTotal(e.totalElements)
      setData(e.content)
    })
  };
  const handleSearch = (values: any) => {
    if (values.dateRange) {
      // const formattedDates = values.dateRange.map((date: string | number | Date | dayjs.Dayjs | null | undefined) => dayjs(date).format('YYYY-MM-DD'));
      let createTime =values.dateRange[0].format('YYYY-MM-DD')
      searchFormData.createTime=createTime
     // values.dateRange[1]  =values.dateRange[0].format('YYYY-MM-DD')

    }
    // console.log(   (values.dateRange[0]).format('YYYY-MM-DD'),'pppppppppppppppppp');
    // 在这里调用 getlist 方法，将表单值传递进去
     getlist({ ...searchFormData, page: '0', size: '10' });
  };
  useEffect(() => {
    console.log('8848999');
    
    getlist({ ...searchFormData })
  
  }, []); // Empty dependency array means this effect runs once after the initial render
  return (
    <>
      <AdvancedSearchForm onSearch={handleSearch} />
      <Searchtable  total={total}  dataSource={data} onPageChange={handlePageChange} />
    </>
  );
};

